#!/bin/sh

source config

mdfile=$bookname"_"$tag.md

echo $mdfile

rm -f $mdfile

echo "generate book: " $mdfile "with " $allchapter "chapters"

#for files in `no $allchapter`
#do
#	prefix=$tag$files"_"

#	cat `ls -l $prefix*.md  |sed -e "/^l/d" |awk '{print $NF}'` >> $mdfile

#	echo "" >>$mdfile

#done

# 用sort的文件排序，代替强行排序，提高效率。

cat `ls -l $tag*.md|sed -e "/^l/d" |awk '{print $NF}' |sort -g ` > $mdfile

sed -e "/^###### 阅读日期.*/d" $mdfile | sed -e "/^###### 读到这里/d" >tmp.md

sed -e "/^$/d" tmp.md |awk '{print $0 "\n"}' >$mdfile

# echo "清理相关文件"

rm -f tmp.md

echo "please check the bookfile : " $mdfile
